package com.blog.mapper;

import com.blog.pojo.Notice;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface NoticeMapper {

    /**
     * 分页查看所有公告
     * @return 公告列表
     */
    @Select("select * from notice order by created desc ")
    List<Notice> listAll();

    /**
     * 查看单个公告
     * @param id 公告id
     * @return 公告实体
     */
    @Select("select * from notice where id = #{id} " +
            "order by created desc")
    Notice listById(Integer id);

    /**
     * 发布公告
     * @param notice 公告实体类
     */
    @Insert("insert into notice (admin_id, title, content, created) values (#{adminId}, #{title}, #{content}, #{created})")
    void insert(Notice notice);

    /**
     * 删除公告
     * @param id 公告id
     */
    @Delete("delete from notice where id = #{id}")
    void delete(Integer id);
}
